//
//  LX_VController.m
//  autolayoutAnimationDemo
//
//  Created by tanchao on 15/12/10.
//  Copyright © 2015年 谈超. All rights reserved.
//

#import "LX_VController.h"
#import "LX_LayoutViews.h"
#import "AnimationUtil.h"
@interface LX_VController ()
@property (nonatomic, strong) NSArray *btnlist;
@property (nonatomic, strong) UIView   *animationView;
@property (nonatomic, strong) UIButton *btn1;
@property (nonatomic, strong) UIButton *btn2;
@property (nonatomic, strong) UIButton *btn3;
@property (nonatomic, strong) UIButton *btn4;
@property (nonatomic, strong) NSLayoutConstraint *layOutConstraint;
@end

@implementation LX_VController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.animationView];
    NSArray *cons =  [self.animationView lx_InnerLayoutForType:LXLayoutInnerTypeCenterBottom referedView:self.view size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 110) offset:CGPointMake(0, 110)];
    self.layOutConstraint = [self.animationView lx_constraintInConstraintsList:cons attribute:NSLayoutAttributeBottom];
}
- (void)viewDidAppear:(BOOL)animated{
    [AnimationUtil tipsLabelMaskAnimation:self.animationView withBeginTime:1.0];
    [AnimationUtil bottomLineAnimation:self.layOutConstraint withView:self.view];
    
}
- (UIView *)animationView{
    if (_animationView == nil) {
        _animationView = [[UIView alloc]init];
        _animationView.backgroundColor = [UIColor yellowColor];
        for (int i = 0; i <= self.btnlist.count -1 ; i++) {
            UIButton *btn = self.btnlist[i];
            btn.tag = i;
            [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            [_animationView addSubview:btn];
            CGFloat xspace = ([UIScreen mainScreen].bounds.size.width - 4 * 90)/5;
            [btn lx_InnerLayoutForType:LXLayoutInnerTypeLeftCenter referedView:_animationView size:CGSizeMake(90, 90) offset:CGPointMake(xspace + (xspace +90)*i, 0)];
        }
    }
    return _animationView;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    if (self.layOutConstraint.constant != 0) {
        [AnimationUtil tipsLabelMaskAnimation:self.animationView withBeginTime:1.0];
    }
    [AnimationUtil bottomLineAnimation:self.layOutConstraint withView:self.view];
}
- (void)btnClick:(UIButton *)btn{
    NSLog(@"点击了第%ld个按钮",(long)btn.tag);
    [AnimationUtil bottomLineAnimation:self.layOutConstraint withView:self.view];
}
#pragma mark 懒加载
- (NSArray *)btnlist{
    if (_btnlist == nil) {
        _btnlist = [NSArray arrayWithObjects:self.btn1,self.btn2,self.btn3,self.btn4, nil];
    }
    return _btnlist;
}
- (UIButton *)btn1{
    if (_btn1 == nil) {
        _btn1 = [[UIButton alloc]init];
        [_btn1 setBackgroundImage:[UIImage imageNamed:@"boy_register"] forState:UIControlStateNormal];
    }
    return _btn1;
}
- (UIButton *)btn2{
    if (_btn2 == nil) {
        _btn2 = [[UIButton alloc]init];
        [_btn2 setBackgroundImage:[UIImage imageNamed:@"boy_register"] forState:UIControlStateNormal];
    }
    return _btn2;
}
- (UIButton *)btn3{
    if (_btn3 == nil) {
        _btn3 = [[UIButton alloc]init];
        [_btn3 setBackgroundImage:[UIImage imageNamed:@"boy_register"] forState:UIControlStateNormal];
    }
    return _btn3;
}
- (UIButton *)btn4{
    if (_btn4 == nil) {
        _btn4 = [[UIButton alloc]init];
        [_btn4 setBackgroundImage:[UIImage imageNamed:@"boy_register"] forState:UIControlStateNormal];
    }
    return _btn4;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
